package multithreadingdemo;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 * @author thangnd
 * email: ducthang.se.gr@gmail.com
 * website: http://www.vi-infotech.com
 */
public class MultithreadingDemo extends Thread{   
    int iNumberThread;
    //Hàm khởi tạo
    public MultithreadingDemo(int iNumThread)  {
        this.iNumberThread =  iNumThread;
    }
    //Nap chong phuong thuc run
    @Override
    public void run() {
        switch (iNumberThread) {
            case 1: 
                System.out.println("Thred thu 1 xu ly: ");
                Thread_A();
                break;
            case 2: 
                System.out.println("Thred thu 2 xu ly: ");
                Thread_B();
                break;
           case 3: 
                System.out.println("Thred thu 3 xu ly: ");
                Thread_C();
                break;
        }   
        try {
            //Thoi gian cho doi xu ly
            //1000 = 1 giay
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            Logger.getLogger(MultithreadingDemo.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Thred " + iNumberThread + " da xu ly xong!");
    }
    public static void main(String[] args) {
        Thread t1 = new MultithreadingDemo(1);
        Thread t2 = new MultithreadingDemo(2);
        Thread t3 = new MultithreadingDemo(3);
        t1.start();
        t2.start();
        t3.start();
    }
    //Cac hanh dong cho cac thread tuong ung
    private static void Thread_A() {
        for (int i= 0; i< 100; i++){
            System.out.print("+ ");
        }
        System.out.print("\n ");
    }
    private static void Thread_B() {
        for (int i= 0; i< 100; i++){
            System.out.print("- ");
        }
        System.out.print("\n ");
    }
    private static void Thread_C() {
        for (int i= 0; i< 100; i++){
            System.out.print("o ");
        }
        System.out.print("\n ");
    }
}
